//
// Created by DengLibin on 2019/1/25 0025.
//

#include <iostream>
#include <vector>
using namespace std;

/**
 * 求最大值的索引 二分
 * @param nums
 * @param startIndex
 * @param endIndex
 * @return
 */
int num79 = 0;

/**
 * 求数组中最大值的索引 时间复杂度要求 O(logN)
 * @param nums
 * @return
 */
int findPeakElement(vector<int>& nums) {
    if(nums.size() <= 1){
        return 0;
    }

    int left = 0;
    int right = nums.size() - 1;
    int mid = 0;
    while (left < right) {
         mid = (left + right) / 2;
                if (nums[mid] > nums[mid+1]) {
                    right = mid;
                }else {
                    left = mid + 1;
                }
        }

    return left;
}
int main79(){

    vector<int > v;
    v.push_back(1);
    v.push_back(5);
    v.push_back(6);
    v.push_back(23);
    v.push_back(3423);
    v.push_back(324);
    v.push_back(34);
    v.push_back(23);
    v.push_back(234);
    v.push_back(3);
    v.push_back(3);
    v.push_back(3);
    v.push_back(3);
    v.push_back(3);
    v.push_back(3);
    v.push_back(34);
    v.push_back(4);
    cout << findPeakElement(v)<<endl;
    cout << num79<<endl;
    return 0;
}